package es.xpt.ysf.commons.location.model;

import es.xpt.ysf.model.Item;

/**
 * Represents a Province or State.
 */

@SuppressWarnings("serial")
public class Province extends Item {

	/**
	 * The code of the country to which the province belongs.
	 */
	private String countryCode;

	
	public Province() {

	}

	public Province(String code, String description) {
		super(code, description);
	}

	/**
	 * This method checks not null fields declared in YSF_CB_PROVINCIA table.
	 * 
	 * @return true if all not null fields have a value
	 */
	public boolean checkRequired() {
		if (getCountryCode() == null)
			return false;
		if (getDescription() == null)
			return false;
		if (getCode() == null)
			return false;
		return true;
	}
	public boolean checkRequiredI18n() {
		if (getDescription() == null)
			return false;
		if (getCode() == null)
			return false;
		if (getLocale() == null)
			return false;
		return true;
	}

	/**
	 * This method checks the primary keys fields.
	 * 
	 * @return true if all fields in the primary Key have a value
	 */
	public boolean checkPrimaryKey() {
		if (countryCode == null)
			return false;
		if (getCode() == null)
			return false;
		return true;
	}

	/**
	 * This method validates the object values
	 * 
	 * @return true if everything is ok
	 */
	public boolean validateData() {
		if (getDescription() != null && getDescription().length() > 80)
			return false;
		if (countryCode != null && countryCode.length() > 15)
			return false;
		if (getCode() != null && getCode().length() > 50)
			return false;
		return true;
	}

	/**
	 * Clone will return identical deep copy of this valueObject. Note, that
	 * this method is different than the clone() which is defined in
	 * java.lang.Object. Here, the retuned cloned object will also have all its
	 * attributes cloned.
	 * 
	 * @return the cloned object
	 * @throws CloneNotSupportedException 
	 */
	public Object clone() throws CloneNotSupportedException {
		Province cloned = (Province)super.clone();
		cloned.setCountryCode(countryCode);
		return cloned;
	}

	
	/**
	 * Set and get methods for the checked fields in the assistant. Not
	 * individual comments generated for these.
	 */

	public void setCountryCode(String pais) {
		this.countryCode = pais;
	}

	public String getCountryCode() {
		return countryCode;
	}

	/**
	 * toString will return String object representing the state of this
	 * valueObject. This is useful during application development, and possibly
	 * when application is writing object states in textlog.
	 */
	public String toString() {
		StringBuffer ret = new StringBuffer();
		ret.append(this.getClass().getName() + " :\n");
		ret.append("description='" + getDescription() + "'\n");
		ret.append("country='" + countryCode + "'\n");
		ret.append("code='" + getCode() + "'\n");
		return ret.toString();
	}
}

// This file has been generated by Logic Generator v1.0
